package com.leetcode.partition6;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/8/6 11:20
 */
public class LC509斐波那契数列 {

    public static int fib(int n) {
        return dynamicProgramming(n);
    }

    //递归
    private static int recursion(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        return recursion(n - 1) + recursion(n - 2);
    }

    //动态规划
    private static int dynamicProgramming(int n) {
        if (n == 0) return 0;
        if (n == 1 || n == 2) return 1;
        int[] dp = new int[n + 1];
        dp[1] = dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        System.out.println(Arrays.toString(dp));
        return dp[n];
    }

    public static void main(String[] args) {
        System.out.println(fib(10));
    }
}
